package com.example.demo.controller;

import com.example.demo.model.MessageInto;
import com.example.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RequestMapping("/message")
@RestController
public class MessageController {
    @Autowired
    public MessageService messageService;

    @RequestMapping("/publish")
    public Boolean publish(MessageInto messageInto) {
        if(!StringUtils.hasLength(messageInto.getTo())
                ||!StringUtils.hasLength(messageInto.getFrom())
                ||!StringUtils.hasLength(messageInto.getMessage())){
            return false;
        }
       Integer result = messageService.publishMessage(messageInto);
        if(result >0){
            return true;
        }
        return true;

    }
    /*
    * 获取留言信息
    * */
    @RequestMapping("/getlist")
    public List<MessageInto> getlist(){
        return messageService.getMessageList();
    }
}
